/**
 * All Rights Reserved , Copyright (C) 2022 , 青岛鼎信通讯股份有限公司
 *
 *MpmProjectFishFirstController
 * 项目任务鱼骨图一级
 *
 * 修改纪录
 * 2022-11-09 版本：1.0 houyuhang 创建。
 * @version 版本：1.0
 * @author 作者：houyuhang
 * 创建日期：2022-11-09
 */

package com.topscomm.mpm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.topscomm.mpm.service.impl.MpmProjectFishFirstService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.topscomm.mpm.controller.auto.MpmProjectFishFirstControllerAuto;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: houyuhang
 * @date: 2022-11-09
 * @description:项目任务鱼骨图一级Controller
 * @modify:
 */
@RestController
@RequestMapping("mpm/projectFishFirst")
public class MpmProjectFishFirstController extends MpmProjectFishFirstControllerAuto implements IMpmProjectFishFirstController {
	@Autowired
	private MpmProjectFishFirstService mpmProjectFishFirstService;
	/**
	 * @author: houyuhang
	 * @date: 2022-11-09
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		return sql.toString();
	}

	/**
	 * @author: houyuhang
	 * @date: 2022-11-09
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	/**
	 * @author: houyuhang
	 * @date: 2022-11-09
	 * @param paraMap
	 * @return
	 * @description:获取任务对应的鱼骨图
	 * @modify:
	 */
	@GetMapping(value = "/queryFishInfo")
	public ResponseResult<Object> queryFishInfo(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			Map<String, Object> resMap = new HashMap<>();
			List<Map<String, Object>> res = mpmProjectFishFirstService.queryFishInfo(paraMap);
			resMap.put("fishbone", res);
			return ResponseResult.ok(resMap);
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}

	/**
	 * @author: houyuhang
	 * @date: 2022-11-09
	 * @param paraMap
	 * @return
	 * @description:任务鱼骨图数据全删全增
	 * @modify:
	 */
	@PostMapping(value = "/insertFishInfo")
	public ResponseResult<Object> insertFishInfo(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			 mpmProjectFishFirstService.insertFishInfo(paraMap);
			return ResponseResult.ok("保存成功");
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}
}

